﻿
<MCol Cols="12" Md="6">
    <MCheckbox @bind-Value="IsSame" Label="显示名称与唯一名称保持一致" TValue="bool" />
</MCol>
<MCol Cols="12" Md="6">
    <MTextField Value="Name" TValue="string" ValueChanged="OnNameChanged" Label="唯一名称" />
</MCol>
<MCol Cols="12" Md="6">
    <MTextField Value="DisplayName" Disabled="IsSame" TValue="string" ValueChanged="DisplayNameChanged" Label="显示名称" />
</MCol>
@code {
    [Parameter]
    public string Class { get; set; }
    [Parameter]
    public string Name { get; set; }
    [Parameter]
    public EventCallback<string> NameChanged { get; set; }
    [Parameter]
    public string DisplayName { get; set; }
    [Parameter]
    public EventCallback<string> DisplayNameChanged { get; set; }

    private bool IsSame { get; set; }

    protected override void OnInitialized()
    {
        IsSame = Name == DisplayName;
    }

    public async Task OnNameChanged(string name)
    {
        Name = name;
        await NameChanged.InvokeAsync(name);

        if(IsSame)
        {
            DisplayName = name;
           await DisplayNameChanged.InvokeAsync(name);
        }
    }
}
